const Router = require("koa-router");
const router = new Router({ prefix: "/essay" });
const { authorverify } = require("../middleware/auth.middleware");
const {
  getallessay,
  getessayanyway,
  getessaydetail,
  changcollect,
  addviews,
  search,
  publish,
  getbyuser,
  deleteessaybyid,
  mangetallessay,
  getnotreadycount,
  getallnotice,
  toreaded,
  allchecke,
  changestate,
} = require("../controller/essay.controller");

//获取一定数量的文章
router.get("/getallessay", getallessay);
//以不同的形式获取文章
router.get("/getessayanyway", getessayanyway);
//获取文章详情
router.get("/getessaydetail/:id", getessaydetail);
//收藏文章或者取消收藏
router.post("/changcollect", authorverify, changcollect);
//增加浏览量
router.put("/addviews/:id", addviews);
//根据标题搜索内容文章
router.get("/search/:content", search);
//发表文章
router.post("/publish", authorverify, publish);
//通过用户id去查询发表的或者收藏的文章
router.get("/getbyuser/:id", getbyuser);
//根据字段audit查询未读的文章消息的数量
router.get("/getnotreadycount/:userid", authorverify, getnotreadycount);
//查询当前登录用户的所有消息
router.get("/getallnotice/:userid", authorverify, getallnotice);
//置所有消息为已读
router.patch("/toreaded/:userid", authorverify, toreaded);

//删除指定文章
router.delete("/deleteessaybyid/:id", authorverify, deleteessaybyid);
//管理员获取所有文章（包含搜索）
router.get("/mangetallessay", authorverify, mangetallessay);
//获取所有需要审核的文章
router.get("/allchecke", authorverify, allchecke);
//改变文章审核状态
router.patch("/changestate/:essayid", authorverify, changestate);

module.exports = router;
